#!/usr/bin/python
import socket
import thread
import time

RECV_FLAG=1

#string type
HOST=raw_input("Server IP: ")
#integer type
PORT=input("Server Port: ")

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((HOST,PORT))

#Define a function for client receive-thread.
def ServiceReply(threadName):
        while 1:
            if RECV_FLAG:
                reply = s.recv(1024)
                stream = "server/> " + reply
                print stream

#Create Python thread
try:
        thread.start_new_thread(ServiceReply, ("Thread receiver",))
except:
        print "Error: unable to creat thread!"

#Python routine entry -> Main loop
while 1:
    txt=raw_input("")
    if len(txt) == 0: continue
    elif cmp(txt, ".CLNTEXIT") == 0:
        s.send(txt)
        time.sleep(1)
        break
    elif cmp(txt, ".SVCEXIT") == 0:
        RECV_FLAG=0
        s.send(txt)
        time.sleep(2)
        break
    else: s.send(txt)

s.close()